import { useState } from "react"

// 通过父组件进行通信

function A({ onGetAName }) {
    const name = 'this is A name'
    return (
        <div>
            this is A component,
            <button onClick={() => onGetAName(name)}>send</button>
        </div>
    )
}
function B({ nameB }) {//{nameB}也可以写成props props.nameB=nameB
    return (<div>
        this is B component,{nameB}
    </div>)
}

function App() {
    const [name, setName] = useState('')
    const getAName = (name) => {
        // console.log(name);
        setName(name)
    }
    return (
        <div>
            this is App
            <A onGetAName={getAName} />
            <B nameB={name} />
        </div>
    )
}
export default App